function fn(nums) {
    let max = 0
    let min = nums[0]
    for (const num of nums) {
        max = Math.max(max, num - min)
        min = Math.min(min, num)
    }
    return max
}
console.log(fn([7, 2, 5, 6, 4, 1]));
